package com.air.thread.pool;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.CountDownLatch;

/**
 * 注意这个多线程方法的类一定要加@Component注解，拿给spring容器管理
 *
 * @author shent
 */
@Component
public class DoThreadPoolDemo {

    @Async("taskExecutor")
    public void doThreadPool(CountDownLatch countDownLatch, int i) {
        long start = System.currentTimeMillis();
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();
        System.out.println("第00" + i + "完成任务，耗时：" + (end - start) + "毫秒，线成名为::" + Thread.currentThread().getName());
        countDownLatch.countDown();
    }
}
